import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/index',
    name: 'index',
    meta: {
      auth: true
    },
    component: () => import('../views/Index.vue'),
    children: [
      {
        path: 'workbench',
        name: 'workbench',

        component: () => import('../views/WorkBench.vue')
      },
      {
        path: 'screen',
        name: 'screen',

        component: () => import('../views/Screen')
      },
      {
        path: 'screenconfigue',
        name: 'screenconfigue',

        component: () => import('../views/ScreenConfigue.vue')
      },
      {
        path: "buildManagement",
        name: 'buildManagement',

        component: () => import('../views/BuildManagement')
      },
      {
        path: 'towerDial',
        name: 'towerDial',

        component: () => import('../views/TowerDial')
      },
      {
        path: 'employeeManagement',
        name: 'employeeManagement',

        component: () => import('../views/EmployeeManagement')
      },
      {
        path: 'residentManagement',
        name: 'residentManagement',
        component: () => import('../views/ResidentManagement')
      }
      ,
      {
        path: 'residentVerification',
        name: 'residentVerification',
        component: () => import('../views/ResidentVerification')
      },
      {
        path: 'teamManagement',
        name: 'teamManagement',
        component: () => import('../views/TeamManagement')
      },
      {
        path: 'paymentManagement',
        name: 'paymentManagement',
        component: () => import('../views/PaymentManagement')
      },
      {
        path: 'decorationReporting',
        name: 'decorationReporting',
        component: () => import('../views/DecorationReporting')
      },
      {
        path: 'complaintsAndSuggestions',
        name: 'complaintsAndSuggestions',
        component: () => import('../views/ComplaintsAndSuggestions.vue')
      },
      {
        path: 'communityActivities',
        name: 'communityActivities',
        component: () => import('../views/CommunityActivities')
      },
      {
        path: 'communityAnnouncements',
        name: 'communityAnnouncements',
        component: () => import('../views/CommunityAnnouncements')
      },
      {
        path: 'informationDisclosure',
        name: 'informationDisclosure',
        component: () => import('../views/InformationDisclosure')
      },
      {
        path: 'adRecommendationPosition',
        name: 'adRecommendationPosition',
        component: () => import('../views/AdRecommendationPosition')
      },
      {
        path: 'accessRecords',
        name: 'accessRecords',
        component: () => import('../views/AccessRecords')
      },
      {
        path: 'doorAccessPermissions',
        name: 'doorAccessPermissions',
        component: () => import('../views/DoorAccessPermissions')
      },
      {
        path: 'visitorManagement',
        name: 'visitorManagement',
        component: () => import('../views/VisitorManagement')
      },
      {
        path: 'simCardDoorAccessManagement',
        name: 'simCardDoorAccessManagement',
        component: () => import('../views/SimCardDoorAccessManagement')
      },
      {
        path: 'visualDoorAccessPermissions',
        name: 'visualDoorAccessPermissions',
        component: () => import('../views/VisualDoorAccessPermissions')
      },
      {
        path: 'cardManagement',
        name: 'cardManagement',
        component: () => import('../views/CardManagement')
      },
      {
        path: 'doorAccessDevices',
        name: 'doorAccessDevices',
        component: () => import('../views/DoorAccessDevices')
      },
      {
        path: 'vehicleManagement',
        name: 'vehicleManagement',
        component: () => import('../views/VehicleManagement')
      },
      {
        path: 'parkingManagement',
        name: 'parkingManagement',
        component: () => import('../views/ParkingManagement')
      },
      {
        path: 'waterMeterDevices',
        name: 'waterMeterDevices',
        component: () => import('../views/WaterMeterDevices')
      },
      {
        path: 'waterMeterAlerts',
        name: 'waterMeterAlerts',
        component: () => import('../views/WaterMeterAlerts')
      },
      {
        path: 'waterMeterRechargeRecords',
        name: 'waterMeterRechargeRecords',
        component: () => import('../views/WaterMeterRechargeRecords')
      },
      {
        path: 'electricityMeterDevices',
        name: 'electricityMeterDevices',
        component: () => import('../views/ElectricityMeterDevices')
      },
      {
        path: 'electricityMeterRechargeRecords',
        name: 'electricityMeterRechargeRecords',
        component: () => import('../views/ElectricityMeterRechargeRecords')
      },
      {
        path: 'alertConfiguration',
        name: 'alertConfiguration',
        component: () => import('../views/AlertConfiguration')
      },
      {
        path: 'controlManagement',
        name: 'controlManagement',
        component: () => import('../views/ControlManagement')
      },
      {
        path: 'couponManagement',
        name: 'couponManagement',
        component: () => import('../views/CouponManagement')
      },
      {
        path: 'overheadObjectThrowing',
        name: 'overheadObjectThrowing',
        component: () => import('../views/OverheadObjectThrowing')
      },
      {
        path: 'personAlert',
        name: 'personAlert',
        component: () => import('../views/PersonAlert')
      } ,
      {
        path: 'vehicleAlert',
        name: 'vehicleAlert',
        component: () => import('../views/VehicleAlert')
      },
      {
        path: 'perimeterIntrusion',
        name: 'perimeterIntrusion',
        component: () => import('../views/PerimeterIntrusion')
      },
      {
        path: 'electricBikeInElevator',
        name: 'electricBikeInElevator',
        component: () => import('../views/ElectricBikeInElevator')
      }
      ,
      {
        path: 'fireExitOccupation',
        name: 'fireExitOccupation',
        component: () => import('../views/FireExitOccupation')
      },
      {
        path: 'dangerousDogRecognition',
        name: 'dangerousDogRecognition',
        component: () => import('../views/DangerousDogRecognition')
      },
      {
        path: 'careObjects',
        name: 'careObjects',
        component: () => import('../views/CareObjects')
      },
      {
        path: 'keyPersonCare',
        name: 'keyPersonCare',
        component: () => import('../views/KeyPersonCare')
      },
      {
        path: 'careAlerts',
        name: 'careAlerts',
        component: () => import('../views/CareAlerts')
      },
      {
        path: 'accessQrCode',
        name: 'accessQrCode',
        component: () => import('../views/AccessQrCode')
      },
      {
        path: 'electronicPass',
        name: 'electronicPass',
        component: () => import('../views/ElectronicPass')
      },
      {
        path: 'accessRecord',
        name: 'accessRecord',
        component: () => import('../views/AccessRecord')
      },
      {
        path: 'smokeDetectorDevices',
        name: 'smokeDetectorDevices',
        component: () => import('../views/SmokeDetectorDevices')
      },
      {
        path: 'roleManagement',
        name: 'roleManagement',
        component: () => import('../views/RoleManagement')
      },
      {
        path: 'maintenanceHandling',
        name: 'maintenanceHandling',
        component: () => import('../views/MaintenanceHandling')
      }
    ]
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {

  if (to.matched.some(item => item.meta.auth)) {
    if (localStorage.getItem("token")) {
      next()
    } else {
      next('/login?returnUrl=' + to.path)
    }
  } else {
    next()
  }

})

export default router

